import streamlit as st
import os
from utils.model_utils import find_latest_best_model
from ultralytics import YOLO

# def main():
#     st.title("Model Performance")
#     model_options = {
#         "YOLOv11n": "yolo11n_best.pt",
#         "YOLOv11s": "yolo11s_best.pt",
#         "YOLOv11m": "yolo11m_best.pt",
#         "YOLOv11l": "yolo11l_best.pt",
#         "YOLOv11x": "yolo11x_best.pt"
#     }
#     selected_model_name = st.selectbox("选择YOLOv11模型", list(model_options.keys()))
#     if st.button("开始验证"):
#         st.write("selected_model_name:", selected_model_name)
#         # 查找最新的 best 模型文件
#         current_dir = os.getcwd()
#         parent_dir = os.path.dirname(current_dir)
#         models_dir = os.path.join(parent_dir, "models", "v2")
#         selected_model_path = os.path.join(models_dir, model_options[selected_model_name])
#         print(current_dir, parent_dir, models_dir, selected_model_path, sep="\n")
#         st.write("selected_model_path:", selected_model_path)
#         if not os.path.exists(selected_model_path):
#             # 如果找不到选定的模型文件，使用最新的最佳模型
#             selected_model_path = find_latest_best_model(models_dir)
#             st.warning(f"找不到选定的模型文件，使用最新的最佳模型: {selected_model_path}")
#         st.write(f"选择的模型文件: {selected_model_path}")
#
#         # 加载模型
#         model = YOLO(selected_model_path)
#         metrics = model.val(data="/Users/xiangliu/Project/cv-sar-aircraft/sar_aircraft_all.yaml", imgsz=1024)  # no arguments needed, dataset and settings remembered
#         st.subheader("Model Performance")
#         st.write(f"Precision: {metrics.box.p}")
#         st.write(f"Recall: {metrics.box.r}")
#         st.write(f"mAP50: {metrics.box.map50}")
#         st.write(f"mAP50-95: {metrics.box.map}")

def main():
    st.title("模型验证性能")
    st.header("yolo11n validation results", divider="blue")
    st.image("./images/yolo11n_val_summary.png", use_container_width=True)
    st.header("yolo11s validation results", divider="green")
    st.image("./images/yolo11s_val_summary.png", use_container_width=True)
    st.header("yolo11m validation results", divider="rainbow")
    st.image("./images/yolo11m_val_summary.png", use_container_width=True)
    st.header("yolo11l validation results", divider="orange")
    st.image("./images/yolo11l_val_summary.png", use_container_width=True)
    st.header("yolo11x validation results", divider="red")
    st.image("./images/yolo11x_val_summary.png", use_container_width=True)

if __name__ == "__main__":
    main()